package test;

import util.Util;

import java.sql.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Random;

public class Perm {
    public static void perm(int[] a, int k, int m) {
        if (k == m - 1) {
            System.out.println(Arrays.toString(a));
        } else {
            for (int i = k; i < m; i++) {
                swap(a, k, i);
                perm(a, k + 1, m);
                swap(a, k, i);
            }
        }
    }

    static void swap(int[] a, int i, int j) {
        int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

    public static void main(String[] args) {
       int [] array = generateRandomArray(4);
        System.out.println(Arrays.toString(array));
       perm(array,0,array.length);
    }

    public static int[] generateRandomArray(int n) {
        int[] array = new int[n];
        for (int i = 0; i < n; i++) {

            array[i] = Util.NonRepeatingRandInt();
        }
        return array;
    }
}
